#include <QApplication>
#include <QDebug>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include "view.hpp"
#include "log.hpp"
#include "cmdvar.hpp"

namespace cloud
{
    CmdHelper* CmdHelper::_inst = nullptr;
    QMutex CmdHelper::_mtx;

    QString default_svr_addr = "47.101.68.49";
    logger::log_level logger::_level;
}

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    cloud::CmdHelper::instance(app, {
            { "l", "log_level. Such as debug/info/warn/error/fatal" },
            { "r", "textbox's scaling ratio. A float number and range is (0,1]" },
            { "t", "request interval time. Once in a while a request will be made to server" },
            { "s", "able to use https or http. Such as 1/0"},
        });

    cloud::logger::setBaseLevel(cloud::logger::str2Level(cloud::CmdHelper::instance()->value("l")));

    DEBUG("used log_level is " + cloud::CmdHelper::instance()->value("l"));
    DEBUG("used scale ratio is " + cloud::CmdHelper::instance()->value("r"));
    DEBUG("used ssl is " + cloud::CmdHelper::instance()->value("s"));

    if (cloud::CmdHelper::instance()->value("s").toInt())
    {
        cloud::default_svr_addr.prepend("https://");
        QSslConfiguration sslConf=QSslConfiguration::defaultConfiguration();
        sslConf.setPeerVerifyMode(QSslSocket::VerifyNone);
        QSslConfiguration::setDefaultConfiguration(sslConf);
    }
    else
    {
        cloud::default_svr_addr.prepend("http://");
    }

    DEBUG("default_svr_addr is " + cloud::default_svr_addr);
    cloud::View view;

    view.fillData();
    view.show();

    return app.exec();
}
